package consturct;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.w3c.dom.NodeList;

import javax.crypto.spec.PSource;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class Test {

    public static void main(String[] args) {
        short s = 1;
//        s = s+1; // 错误 需要向下转型 强转
        s+=1; // 默认编译为 s = (short) (s+1);
        System.out.println(s);
//        s += 1;
//        System.out.println("subClass1-------------------");
//        SubClass subClass = new SubClass();
//        System.out.println("subClass2-------------------");
//        SubClass subClass1 = new SubClass("代号1","代号2");
//
//        //StringBuffer 线程安全 所有的方法都使用synchronized修饰
//        StringBuffer str1 = new StringBuffer();
//        //非线程安全
//        StringBuilder str2 = new StringBuilder();
//
//        // Integer 表示范围是 -128到127
//        Integer i = Integer.valueOf(129);

//        Double d1 = Double.valueOf(100.0);
//        Double d2 = 100.0;
//        System.out.println(d1==d2);//false

        //boolean
//        Boolean b1 = Boolean.valueOf(false); //  public static final Boolean TRUE = new Boolean(true);
//        Boolean b2 = Boolean.valueOf(false);
//        System.out.println(b1 == b2);

        //抽象类
        // 字节输入输出流 InputStream OutputStream
        // 字符输出输出流 Reader  Writer
//        InputStream in ;
//        OutputStream out;
//
//        Reader r;
//        Writer w;

//        Object o = new Object();
//        HashMap map = new HashMap();
//        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
//        concurrentHashMap.put("1","111");


//        // 时间类
//        LocalDate localDate = LocalDate.now();
//
//        // 获取当月第一天
//        LocalDate firstDayOfMonth = localDate.with(TemporalAdjusters.firstDayOfMonth());
//
//        // 获取当月最后一天
//        LocalDate lastDayOfMonth = localDate.with(TemporalAdjusters.lastDayOfMonth());
//
//        // 下一天
//        LocalDate nextDay = lastDayOfMonth.plusDays(1);
//
//        // 当年最后一天
//        LocalDate dayOfThisYear = localDate.with(TemporalAdjusters.lastDayOfYear());
//
//        // 2021年最后一个周日
//        LocalDate lastSun = LocalDate.parse("2021-12-31").with(TemporalAdjusters.lastInMonth(DayOfWeek.SUNDAY));
//
//
//        System.out.println("localDate:"+localDate);
//        System.out.println("获取当月第一天"+firstDayOfMonth);
//        System.out.println("获取当月最后一天"+lastDayOfMonth);
//        System.out.println("下一天"+nextDay);
//        System.out.println("当年最后一天"+dayOfThisYear);
//        System.out.println("2021年最后一个周日"+lastSun);


//        // 集合
//        List list = Arrays.asList("1","2","3");
//        System.out.println(list.size());
//        System.out.println(list.get(0));
//        System.out.println(list.get(1));
//        // Array.asList 集合不能进行 add remove 等操作
//        list.add("33");
//        ArrayList arrayList = new ArrayList();
//
//        String a = "erere";
//        a.replaceAll("","333");



        // Spring
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext();
        //
        BeanFactory beanFactory = new DefaultListableBeanFactory();


        //跳表
        ConcurrentSkipListMap skipListMap = new ConcurrentSkipListMap();


    }


    // 线程池
    // 参数  核心线程数、最大线程数、非核心线程存活时间、时间单位、任务队列（当达到核心线程数时，再由新的任务进来时，放入该队列，队列满时，才会创建非核心线程来执行任务）、拒绝策略（默认 AbortPolicy-拒绝 不会接受新的任务）
//    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10,15,300, TimeUnit.SECONDS,new ArrayBlockingQueue<>(10), new ThreadPoolExecutor.AbortPolicy());
//
//    AtomicInteger atomicInteger = new AtomicInteger(0);
//
//    ReentrantLock reentrantLock = new ReentrantLock();
//    Semaphore semaphore = new Semaphore(1);
//
//    List list = Collections.synchronizedList(new ArrayList<>());





    /**
     * 死锁
     */
//    private static final Object r1 = new Object();
//    private static final Object r2 = new Object();

//
//    public static void main(String[] args) {
//        new Thread(
//            () ->{
//                synchronized (r1){
//                    System.out.println(Thread.currentThread()+" get Resource1:=======>");
//                    try {
//                        Thread.sleep(1000);
//                    }catch (Exception e){
//                        e.printStackTrace();
//                    }
//                    System.out.println(Thread.currentThread() + " waiting for grt resource2");
//                    synchronized (r2){
//                        System.out.println(Thread.currentThread() + " get resource2");
//                    }
//
//                }
//            },"线程1"
//        ).start();
//
//
//        new Thread(
//                () ->{
//                    synchronized (r2){
//                        System.out.println(Thread.currentThread()+" get Resource2:=======>");
//                        try {
//                            Thread.sleep(1000);
//                        }catch (Exception e){
//                            e.printStackTrace();
//                        }
//                        System.out.println(Thread.currentThread() + " waiting for grt resource1");
//                        synchronized (r1){
//                            System.out.println(Thread.currentThread() + " get resource1");
//                        }
//
//                    }
//                },"线程2"
//        ).start();
//    }

}
